
#include <config.h>
#include <genericrenamedialog.h>

GenericRenameDialog::GenericRenameDialog(QWidget *parent)
  : QDialog(parent)
{
  _gui.setupUi (this);
  setWindowTitle(CE_TOOL_NAME);
}

void GenericRenameDialog::SetType(const QString& mode, const QString& type)
{
  _gui.labelRename->setText(mode+ " " + type);
}

void GenericRenameDialog::SetType(const QString &type)
{
  _gui.labelRename->setText ("Rename " + type);
}

void GenericRenameDialog::SetCategory(const Category &category, bool chopBaseName)
{
  Category c = category;

  if (c.GetNumberOfStages() > 0 && chopBaseName)
    {
      _catgoryBaseName = c.GetBaseName();
      c.PopFront();
    }
  else
    {
      _catgoryBaseName = "";
    }

  _gui.lineEditCategory->setText (c.GetFullName());
  _gui.lineEditCategory->setFocus();
  _gui.lineEditCategory->selectAll ();
}


Category GenericRenameDialog::GetCategory()
{
  Category cat (_catgoryBaseName);
  cat.Add(_gui.lineEditCategory->text ());
  return cat;
}

void GenericRenameDialog::SetName(const QString &name)
{
  _gui.lineEditName->setText (name);
}

QString GenericRenameDialog::GetName() const
{
  return _gui.lineEditName->text ();
}

void GenericRenameDialog::HideCategory ()
{
  _gui.lineEditCategory->setVisible (false);
  _gui.labelCategory->setVisible (false);
}


void GenericRenameDialog::HideName()
{
  _gui.lineEditName->setVisible (false);
  _gui.labelName->setVisible (false);
}


void GenericRenameDialog::on_pushButtonCancel_clicked()
{
  reject();
}

void GenericRenameDialog::on_pushButtonOk_clicked()
{
  accept();
}

Category GenericRenameDialog::GetCategory(QWidget *parent, const QString &mode, const QString &type, const Category &category)
{
  GenericRenameDialog dlg (parent);
  dlg.SetType(mode, type);
  dlg.SetCategory(category);
  dlg.HideName ();
  if (dlg.exec() == QDialog::Accepted)
    {
      return dlg.GetCategory();
    }

  return category;
}



QString GenericRenameDialog::GetName(QWidget *parent, const QString &mode, const QString &type, const QString &name, bool returnNull)
{
  GenericRenameDialog dlg (parent);
  dlg.SetType(mode, type);
  dlg.SetName(name);
  dlg.HideCategory ();
  if (dlg.exec() == QDialog::Accepted)
    {
      return dlg.GetName();
    }

  if (returnNull)
    {
      return QString::Null();
    }
  return name;
}

